package com.liangtian.mdm.system.uniformSelect.service.impl;

import com.liangtian.mdm.system.uniformSelect.dao.SysUniformSelectDao;
import com.liangtian.mdm.system.uniformSelect.model.SysUniformSelect;
import com.liangtian.mdm.system.uniformSelect.service.SysUniformSelectService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SysUniformSelectServiceImpl implements SysUniformSelectService {

    @Autowired
    private SysUniformSelectDao sysUniformSelectDao;

    // Session中保存的当前登录用户的信息
    //@Value("${ConstantBean.CURRENT_SESSION_USER}")
    //private String ConstantBean.CURRENT_SESSION_USER;

    @SuppressWarnings({"unchecked", "rawtypes"})
    @Override
    public PageInfo getUniformSelectLstByCond(Map<String, Object> map) {
        PageInfo<List<SysUniformSelect>> pageInfo = null;
        try {
            Object pNo = map.get("pageNum");
            int pageNum, pageSize;
            // export
            if (pNo != null && !"NaN".equals(pNo)) {
                pageNum = Integer.parseInt(pNo.toString());// 页码
            } else {
                pageNum = 1;
            }
            // pageSize=0时不分页
            pageSize = Integer.parseInt(map.get("limit").toString());// 模型定义页面要显示数据条数
            // 例如
            // 10,20,50,100
            PageHelper.startPage(pageNum, pageSize);// 开始分页标志（当前页，显示条数）

            List<SysUniformSelect> list = sysUniformSelectDao.getUniformSelectLstByCond(map);
            pageInfo = new PageInfo(list);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return pageInfo;
    }

    @Override
    public int insertUniformSelect(SysUniformSelect query) {
        return sysUniformSelectDao.insertUniformSelect(query);

    }

    @Override
    public int checkGJQueryCount(SysUniformSelect query) {
        Map<String, Object> map = new HashMap<>();
        map.put("model_id", query.getModel_id());
        map.put("attr_id", query.getAttr_id());
        return sysUniformSelectDao.checkGJQueryCount(map);
    }

    @Override
    public void updateGJQueryByAttrId(SysUniformSelect query) {
        sysUniformSelectDao.updateGJQueryByAttrId(query);

    }

    @Override
    public SysUniformSelect getGJQueryByAttrId(SysUniformSelect query) {
        return sysUniformSelectDao.getGJQueryByAttrId(query);
    }

    @Override
    public int deleteGJQueryByAttrIds(Map<String, Object> map) {
        return sysUniformSelectDao.deleteGJQueryByAttrIds(map);
    }

    @Override
    public List<SysUniformSelect> getUniformSelectLstByCond(SysUniformSelect query) {
        Map<String, Object> map = new HashMap<>();
        map.put("model_id", query.getModel_id());
        return sysUniformSelectDao.getUniformSelectLstByCond(map);
    }

}
